package com.Ahmad.FingerLock;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.RemoteViews;

public class Widget extends AppWidgetProvider {

    @Override
    public void onEnabled(Context context) {
        AppWidgetManager mAppWidgetManager = AppWidgetManager.getInstance(context);
        Intent intent = new Intent();
        Log.i("PackageName", context.getPackageName());
        intent.setClassName(context.getPackageName(), context.getPackageName());
        PendingIntent mPendingIntent = PendingIntent.getService(context, 0, intent, 0);
        RemoteViews mRemoteViews = new RemoteViews(context.getPackageName(), R.xml.hello_widget_provider);
        mRemoteViews.setOnClickPendingIntent(R.id.imgLock, mPendingIntent);
        ComponentName mComponentName = new ComponentName(context.getPackageName(), Widget.class.getName());
        mAppWidgetManager.updateAppWidget(mComponentName, mRemoteViews);
    }

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        for (int i = 0; i < appWidgetIds.length; i++) {
            Intent intent = new Intent(context, MainActivity.class);
            PendingIntent mPendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
            RemoteViews mRemoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
            mRemoteViews.setOnClickPendingIntent(R.id.imgLock, mPendingIntent);
            appWidgetManager.updateAppWidget(appWidgetIds[i], mRemoteViews);
        }
    }

}
